﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;



namespace Data {
    public class DataAcces {
       

        static System.Data.EntityClient.EntityConnection ec = new System.Data.EntityClient.EntityConnection("name=SAWDBEntities");
     
        //COMPARTIMOS CONEXION, NO SE PROMUEVE A DISTRIBUIDA
       // SAWDBEntities cnn1 = new SAWDBEntities(ec);
       //SAWDBEntities cnn2 = new SAWDBEntities(ec);

        //CONEXIONES DISTINTAS
         SAWDBEntities cnn1 = new SAWDBEntities();
          SAWDBEntities cnn2 = new SAWDBEntities();

        public DataAcces() {
            //Trace.Listeners.Add(new TextWriterTraceListener(@"C:\Users\jose.gonzalez\Desktop\A.txt"));
          //  ec.Open();

        }

        public string coneccion() {
           
            return cnn1.Connection.ConnectionString;
        }

        public bool checkConnection() {

            return cnn1.Connection.Equals(cnn2.Connection);
        }

        public IEnumerable<Cliente> getCLiente() {
            return from c in cnn1.Cliente
                   select c;
        }

        public IEnumerable<factura> getFactura() {
            return from f in cnn2.factura 
                   select f; 
        }

        public bool Grabar()  
    {

        //using (ec) {
            //cnn1.Connection.Open();
            cnn1.SaveChanges();
           // cnn1.Connection.Close();
            
            //cnn2.Connection.Open();
            cnn2.SaveChanges();
            //cnn2.Connection.Close();
            return true;
        //}
     
            }

        public bool Grabar2() {
           
          //  using (ec) {
          //  throw new Exception("Mi ex");
            cnn2.SaveChanges();

                return true;
           // }
      
        }
    
    
    }



}
